﻿using System;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json.Serialization;
using book;
using Newtonsoft.Json;
using JsonSerializer = System.Text.Json.JsonSerializer;

namespace app1;

class Program
{
    enum MyEnum
    {
        ss,
    }

    class MyClass
    {
        
    }

    struct MyStruct
    {
        
    }


    interface IInterface
    {
        int length { get; set; }
    }
    
    class ClassBase : IInterface
    {
        public int num;
        public int length { get; set; }
    }

    [JsonSerializable(typeof(MyClass222222))]
    class MyClass222222 : ClassBase
    {
        public string s1;
        public string s2;
        public double d1;
    }
    
    //Json抽象只适用于普通类  不支持抽象类和接口, 在Newtonsoft.Json中反序列化至object会返回Newtonsoft.Json.Linq.JObject
    
    static void Main(string[] args)
    {

        string str = "[1,2,3,4,5]";
        var span = str.AsSpan().Slice(1, str.Length - 2);
        Console.WriteLine(new string(span));
        return;
        
        // int[][][] kk = new();
        
        // Console.WriteLine(JsonConvert.SerializeObject(kk));
        var type = typeof(int[,,]);

        Console.WriteLine(">>>>>>>>>>>>>>>>" + typeof(int[,,]).GetElementType());


    }

    private static string CreateFunc(int count)
    {
        var s = typeof(ValueTuple<,,,,,,,>);
        string str = @"
        public interface IJsonFormat2 : IJsonFormat
        {
           void Serialize<TType, T1, T2>(IBufferWriter<char> writer, ref TType item, ref T1 t1, ref T2 t2);
           TType Deserialize<TType, T1, T2>(in Span<char> str);
        }
        ";

        StringBuilder sb = new StringBuilder();
        sb.AppendLine($"public interface IJsonFormat{count} : IJsonFormat");
        sb.AppendLine("{");
        sb.AppendLine("    " + $"void Serialize<TType, {CreateGenericsArgument(count)}>(IBufferWriter<char> writer, ref TType item, {CreateGenericsParameter(count)});");
        sb.AppendLine("    " + $"TType Deserialize<TType, {CreateGenericsArgument(count)}>(in Span<char> str);");
        sb.AppendLine("}");
        return sb.ToString();
    }

    private static string CreateGenericsArgument(int count)
    {
        var sb = new StringBuilder();
        for (int i = 0; i < count; i++)
        {
            sb.Append($"T{i + 1}");
            if (i < count - 1)
            {
                sb.Append(",");
            }
        }

        return sb.ToString();
    }

    private static string CreateGenericsParameter(int count)
    {
        var sb = new StringBuilder();
        for (int i = 0; i < count; i++)
        {
            sb.Append($"ref T{i + 1} t{i + 1}");
            if (i < count - 1)
            {
                sb.Append(",");
            }
        }

        return sb.ToString();
    }

}

/*
 *数字0分配从char[]读写--完成
 *泛型类
 */


/*
 *      sbyte i8;
        byte u8;
        short i16;
        ushort u16;
        int i32;
        uint u32;
        long i64;
        ulong u64;
        float f32;
        double f64;
        bool bbbb;
        Int128 i128;
        UInt128 u128;
        BigInteger sssssss;
        IntPtr ip;
        UIntPtr uip;
       
        
        Guid g1;
        ValueTuple<int, int> ssss;
        
        
        List<int> s1;
        HashSet<int> s2;
        Dictionary<string, string> s3;
        Queue<uint> ss;
        Stack<string> sssss;
        
        ConcurrentDictionary<string, string> ooo;
        ConcurrentQueue<string> ccc;
        ConcurrentStack<string> ssssss;
        ConcurrentBag<string> uul;
        
        Vector2 v2;
        Vector3 v3;
        Vector4 v4;
        Quaternion q1;
        int[] a1;


        DateTime dt1 = new DateTime();
        TimeSpan ts;

       
        Uri
        TimeZoneInfo
 *
 * 
 */